package SM.BusinessLogic;

import javax.servlet.http.HttpServletRequest;

public class SessionVariables {

	private static String CURRENT_USER = "SM_USER";
	private static String SOC_NAME = "SM_SOC";
	private static String DEPT_STR = "SM_DEPT";
	
	private static void SetAttribute(String id, String value, HttpServletRequest req)
	{
		javax.servlet.http.HttpSession session = req.getSession();
		
		if(session == null)
		{
			System.out.println("Session is null.");
			return;
		}
		
		session.setAttribute(id,value);
		
	}
	
	private static String GetAttribute(String id, HttpServletRequest req)
	{
		javax.servlet.http.HttpSession session = req.getSession();
		
		if(session == null)
		{
			System.out.println("Session is null.");
			return null;
		}
		
		String str = (String)session.getAttribute(id);
		
		if(str == null)
		{
			System.out.println("Value for " + id + " is null.");
			return null;
		}
		
		return str;
	}
	
	public static String GetUser(HttpServletRequest req)
	{
		return GetAttribute(CURRENT_USER, req);
	}
	
	public static void SetUser(String user, HttpServletRequest req)
	{
		SetAttribute(CURRENT_USER,user,req);
	}
	
	public static String GetSocName(HttpServletRequest req)
	{
		return GetAttribute(SOC_NAME,req);
	}
	
	public static void SetSocName(String soc, HttpServletRequest req)
	{
		SetAttribute(SOC_NAME,soc,req);
	}
	
	public static String GetDept(HttpServletRequest req)
	{
		return GetAttribute(DEPT_STR,req);
	}
	
	public static void SetDept(String str, HttpServletRequest req)
	{
		SetAttribute(DEPT_STR,str,req);
	}
}